﻿
@{
    ViewBag.Title = "BizTypeAdd";
    Layout = "~/Views/Shared/layoutCommon.cshtml";
}

@model OF.Component.Model.BizTypeInfo

@section style{
    <style>
        .form-horizontal .control-label {
            width: 20%;
            float: left;
            text-align: right;
        }

        .col-sm-3 {
            width: 80%;
            float: left;
        }
    </style>
}
<form id="form1" class="form-horizontal">
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">分类名称：</label>
                        <div class="col-sm-3">
                            <select class="form-control" style="width:300px;" name="selMasterBizType" id="selMasterBizType"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">名称：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.BizTypeName" style="width:300px;" name="txtName" maxlength="50" id="txtName" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">拼音：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.BizTypePinYin" style="width:300px;" name="txtPinYin" maxlength="50" id="txtPinYin" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">Icon：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.BizTypeIcon" style="width:300px;" name="txtIcon" maxlength="50" id="txtIcon" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">排序：</label>
                        <div class="col-sm-3">
                            <input type="text" class="form-control" value="@Model.BizTypeSort" style="width:300px;" name="txtSort" maxlength="8" id="txtSort" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="name">首页显示：</label>
                        <div class="col-sm-3 ">
                            <input id="chkIsShowIndex" class="color-checkbox" type="checkbox" name="chkIsShowIndex" />
                            <label for="chkIsShowIndex"></label>
                        </div>
                    </div>
                </div>
                <div class="box-footer text-center">
                    <button class="btn btn-primary" type="button" id="btnSave">确 定 </button>
                    <button class="btn" type="button" id="cancel">取 消 </button>
                </div>
            </div>

        </div>
        <!-- /.row -->
    </section>

</form>
@section scriptsBottom{
    <script type="text/javascript">
       $(document).ready(function () {
           initFormValidate();
           initMasterBizType();
           $("#btnSave").click(function(){
               save();
           });
           $("#cancel").click(function () {
               BMCW.closeTopLayer();
           });
           if(@Model.IsShowIndex==1)
           {
               $("#chkIsShowIndex").attr("checked","checked");
           }
       });
       function initFormValidate() {
           $("#form1").bootstrapValidator({
               submitHandler: function (valiadtor, loginForm, submitButton) {
                   valiadtor.defaultSubmit();
               },
               fields: {
                   selMasterBizType: {
                       validators: {
                           notEmpty: {
                               message: '请选择分类'
                           }
                       }
                   },
                   txtName: {
                       validators: {
                           notEmpty: {
                               message: '名称不能为空'
                           },
                           stringLength: {
                               /*长度提示*/
                               min: 1,
                               max: 50,
                               message: '名称长度必须在1到50之间'
                           }
                       }
                   },
                   txtSort: {
                       validators: {
                           notEmpty: {
                               message: '排序不能为空'
                           },
                           stringLength: {
                               /*长度提示*/
                               min: 1,
                               max: 8,
                               message: '排序长度必须在1到10之间'
                           },
                           digits: {
                               message: '排序只能是数字'
                           }
                       }
                   }

               }
           });
       }

       function save()
       {
           var bootstrapValidator = $("#form1").data('bootstrapValidator');
           bootstrapValidator.validate();

           if (bootstrapValidator.isValid()) {
               var isShow = 0;
               if($("#chkIsShowIndex").prop("checked")==true)
               {
                   isShow = 1;
               }
               var url = '@Url.Action("SaveBizType", "BasicData")'
               BMCW.ajax({
                   url: url,
                   type: "Post",
                   data: {
                       BizTypeID:@Model.BizTypeID,
                       MasterBizTypeID: $("#selMasterBizType").val(),
                       BizTypeName: $("#txtName").val(),
                       BizTypeSort: $("#txtSort").val(),
                       IsShowIndex:isShow,
                       BizTypeIcon: $("#txtIcon").val(),
                       BizTypePinYin:$("#txtPinYin").val()
                   },
                   success: function (o) {
                       if (o.status == 0) {
                           BMCW.msg("保存成功",function(){
                               BMCW.getTopSelectedWin().search();
                           });
                       } else {
                           BMCW.alert("保存失败");
                       }
                   }
               });
           }
       }

       //一级分类
       function initMasterBizType()
       {
           var mid = @Model.MasterBizTypeID;
           $("#selMasterBizType").append("<option value=''>请选择一级分类</option>");
           var url = '@Url.Action("GetMasterBizTypeList", "BasicData")'
           BMCW.ajax({
               url: url,
               type: "GET",
               success: function (o) {
                   if (o.status == 0) {
                       $.each(o.data, function (i) {
                           var sel = "";
                           if(o.data[i].MasterBizTypeID == mid)
                           {
                               sel = "selected='true'";
                           }
                           $("#selMasterBizType").append("<option value='" + o.data[i].MasterBizTypeID + "' " + sel + ">" + o.data[i].MasterBizTypeName + "</option>");
                       });
                   }
               }
           });
       }
    </script>
}

